home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicBorderFactory.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  156 lines

  1. /*
  2.  * @(#)BasicBorderFactory.java    1.5 98/01/30
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.basic;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.border.*;
  25. import com.sun.java.swing.plaf.*;
  26.  
  27. import java.awt.Component;
  28. import java.awt.Insets;
  29. import java.awt.Dimension;
  30. import java.awt.Color;
  31. import java.awt.Graphics;
  32. import java.io.Serializable;
  33.  
  34.  
  35. /**
  36.  * Factory object that can vend Borders appropriate for the basic L & F.
  37.  * @version 1.5 01/30/98
  38.  * @author Georges Saab
  39.  */
  40.  
  41. public class BasicBorderFactory
  42. {
  43.  
  44.   private static Border toggleButtonBorder;
  45.   private static Border radioButtonBorder;
  46.   private static Border buttonBorder;
  47.   private static Border menuBarBorder;
  48.  
  49.   public static Border getMenuBarBorder() {
  50.     if (menuBarBorder == null){
  51.       menuBarBorder = new BasicMenuBarBorder();
  52.     }
  53.     return menuBarBorder;
  54.   }
  55.  
  56.   public static Border getButtonBorder() {
  57.     if (buttonBorder == null){
  58.       buttonBorder = new BasicButtonBorder();
  59.     }
  60.     return buttonBorder;
  61.   }
  62.  
  63.   public static Border getToggleButtonBorder() {
  64.     if (toggleButtonBorder == null) {
  65.       toggleButtonBorder = new BasicToggleBorder();
  66.     }
  67.     return toggleButtonBorder;
  68.   }
  69.  
  70.   public static Border getRadioButtonBorder() {
  71.     if (radioButtonBorder == null) {
  72.       radioButtonBorder = new BasicRadioBorder();
  73.     }
  74.     return radioButtonBorder;
  75.   }
  76.  
  77.  
  78.   private static class BasicToggleBorder extends AbstractBorder {
  79.  
  80.         public void paintBorder(Component c, Graphics g, int x, int y, 
  81.                                 int width, int height) {
  82.                 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false);
  83.     }
  84.  
  85.         public Insets getBorderInsets(Component c)       {
  86.             return new Insets(2, 2, 2, 2);
  87.         }
  88.     }
  89.  
  90.     private static class BasicRadioBorder extends AbstractBorder {
  91.  
  92.         public void paintBorder(Component c, Graphics g, int x, int y, 
  93.                                 int width, int height) {
  94.  
  95.             if (c instanceof AbstractButton) {
  96.                 AbstractButton b = (AbstractButton)c;
  97.                 ButtonModel model = b.getModel();
  98.  
  99.                 if (model.isArmed() && model.isPressed() || model.isSelected()) {
  100.                     BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height);
  101.                 } else {
  102.                     BasicGraphicsUtils.drawBezel(g, x, y, width, height, 
  103.                                          false, b.isFocusPainted() && b.hasFocus());
  104.                 }
  105.             } else {    
  106.                 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false);
  107.             }
  108.         }
  109.  
  110.         public Insets getBorderInsets(Component c)       {
  111.             return new Insets(2, 2, 2, 2);
  112.         }
  113.     }
  114.  
  115.   private static class BasicButtonBorder extends AbstractBorder {
  116.     public void paintBorder(Component c, Graphics g, int x, int y, 
  117.                             int width, int height) {
  118.       boolean isPressed = false;
  119.       boolean isDefault = false;
  120.       
  121.       if (c instanceof AbstractButton) {
  122.     AbstractButton b = (AbstractButton)c;
  123.     ButtonModel model = b.getModel();
  124.     
  125.     isPressed = model.isPressed() && model.isArmed();
  126.  
  127.         if (c instanceof JButton) {
  128.             isDefault = ((JButton)c).isDefaultButton();
  129.         }
  130.       }    
  131.       BasicGraphicsUtils.drawBezel(g, x, y, width, height, 
  132.                    isPressed, isDefault);
  133.     }
  134.     public Insets getBorderInsets(Component c)       {
  135.         if (c instanceof JButton && ((JButton)c).isDefaultButton()) {
  136.             // leave room for default visual
  137.             return new Insets(2,2,3,3);
  138.         }
  139.         return new Insets(1,1,2,2);
  140.     }
  141.   }
  142.  
  143.     private static class BasicMenuBarBorder extends AbstractBorder
  144.     {
  145.     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  146.         BasicGraphicsUtils.drawGroove(g, 0, height-2, 
  147.                       width, height);
  148.     }
  149.     
  150.     public Insets getBorderInsets(Component c)       {
  151.         return new Insets(0, 0, 2, 0);
  152.     }
  153.     }
  154.     
  155. }
  156.